﻿<%--

// Matt's TinyMVC Copyright (c) 2009 Matt J. Crouch

// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the "Software"), to deal in the Software without restriction, 
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
// subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all copies
// or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--%>
     
<%@ Import Namespace="PurchasingSampleApplication" %>
<%@ Page 
        Language="C#"
        CodeBehind="PurchasingDepartmentHome.aspx.cs"
        Inherits="PurchasingSampleApplication.PurchasingDepartmentHome"
        AutoEventWireup="true"
        EnableViewState="false"
        ClientIDMode="Static" 
        EnableSessionState="True"
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Purchasing Department Application</title>
</head>
<body>
    <h1>Matt's TinyMVC Sample Application</h1>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1" />
        <asp:UpdatePanel runat="server" UpdateMode="Always" ID="UpdatePanel1">
            <ContentTemplate>
                <asp:Button runat="server" ID="CreateNewPurchaseOrderButton"
                    ModelID='<%# Controller.ID %>'
                    ModelCommandName="CreateNewPurchaseOrder"
                    OnCommand="ExecuteCommand"
                    Text="Create New Purchase Order" />  

                <table style="width: 100%;">
                    <tr>
                        <td>PO Number:</td>
                        <td>
                            <asp:TextBox ID="TextBox1" runat="server"
                                OnDataBinding="RegisterForUpdate"
                                ModelID='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ID  %>'
                                ModelPropertyName="PONumber"
                                Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>'
                                Text='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.PONumber %>' />
                        </td>
                        <td>Date Created:</td>
                        <td>
                            <asp:TextBox ID="TextBox2" runat="server"
                                    Enabled="false"
                                    ModelID='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ID  %>'
                                    Text='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.DateCreated %>' />
                        </td>
                    </tr>
                    <tr>
                        <td>Ship To Name:</td>
                        <td>
                            <asp:TextBox ID="TextBox3" runat="server"
                                OnDataBinding="RegisterForUpdate"
                                ModelID='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ID %>'
                                ModelPropertyName="ShipToName"
                                Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>'
                                Text='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ShipToName %>' />
                        </td>
                        <td>Ship To Address:</td>
                        <td>
                            <asp:TextBox ID="TextBox4" runat="server"
                                OnDataBinding="RegisterForUpdate"
                                ModelID='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ID %>'
                                ModelPropertyName="ShipToAddress"
                                Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>'
                                Text='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ShipToAddress %>' />
                        </td>
                    </tr>
                    <tr>
                        <td>Requisitioner:</td>
                        <td>
                            <asp:TextBox ID="TextBox5" runat="server" 
                                OnDataBinding="RegisterForUpdate"
                                ModelID='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ID %>'
                                ModelPropertyName="Requisitioner"
                                Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>'
                                Text='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.Requisitioner %>'                             />
                        </td>
                        <td>Shipping Type:</td>
                        <td>
                             <asp:DropDownList ID="DropDownList1" runat="server"
                                OnDataBinding="RegisterForUpdate"
                                AutoPostBack="true"
                                ModelID='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ID %>' 
                                ModelPropertyName="ShipVia"
                                SelectedValue='<%# (int)((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ShipVia %>' 
                                OnSelectedIndexChanged="ExecuteCommand"
                                ModelCommandName="UpdateShippingMethod"                               
                                Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>'>
                                    <asp:ListItem Enabled="false"/>
                                    <asp:ListItem Text="Overnight" Value="0" />
                                    <asp:ListItem Text="SecondDay" Value="1" />
                                    <asp:ListItem Text="PriorityMail" Value="2" />
                             </asp:DropDownList>

                        </td>
                    </tr>
                    <tr>
                        <td>                
                            <asp:Button runat="server" ID="PreviousButton" Text=" < "
                                ModelID='<%# Controller.ID %>'
                                ModelCommandName="MovePrevious"
                                OnCommand="ExecuteCommand"
                                Enabled='<%# ((PurchasingDepartmentController)Controller).CanMovePrevious %>'  />
                            <asp:Button runat="server" ID="NextButton" Text=" > "
                                ModelID='<%# Controller.ID %>'
                                ModelCommandName="MoveNext"
                                OnCommand="ExecuteCommand"
                                Enabled='<%# ((PurchasingDepartmentController)Controller).CanMoveNext %>'  />

                        </td>
                        <td>
                            <asp:Button runat="server" ID="EditButton" Text="Edit"
                                ModelID='<%# Controller.ID %>'
                                Enabled='<%# !((PurchasingDepartmentController)Controller).IsInEditMode %>'
                                ModelCommandName="BeginEdit"
                                OnCommand="ExecuteCommand" />
                            <asp:Button runat="server" ID="SaveButton" Text="Save"
                                ModelID='<%# Controller.ID %>'
                                ModelCommandName="SaveCurrentPurchaseOrder"
                                OnCommand="ExecuteCommand"
                                Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>' />

                            <%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrderIndex %> of 
                            <%# ((PurchasingDepartmentController)Controller).PurchaseOrderCount %> 

                        </td>
                    </tr>
                    <tr>
                        <td colspan="3"><%# ((PurchasingDepartmentController)Controller).StatusMessage %></td>
                    </tr>
                </table>

                <asp:Button runat="server" ID="NewLineItemButton"
                    Text="New Line Item"
                    Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>'
                    ModelID='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.ID %>'
                    ModelCommandName="AddLineItem"
                    OnCommand="ExecuteCommand" />

                <asp:GridView runat="server" ID="OrderItemsGrid"
                    AutoGenerateColumns="false"
                    ShowHeaderWhenEmpty="true"
                    DataSource='<%# ((PurchasingDepartmentController)Controller).CurrentPurchaseOrder.LineItems %>'>
                    <Columns>
                        <asp:TemplateField HeaderText="Item Number">
                            <ItemTemplate>
                                <asp:TextBox runat="server" ID="ItemNumberTextBox" ClientIDMode="Predictable"
                                    OnDataBinding="RegisterForUpdate"
                                    ModelID='<%# ((OrderLineItem)Container.DataItem).ID %>'
                                    ModelPropertyName="ItemNumber"
                                    Text='<%# ((OrderLineItem)Container.DataItem).ItemNumber %>'
                                    Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Item Description">
                            <ItemTemplate>
                                <asp:TextBox runat="server" ID="ItemDescriptionTextBox" ClientIDMode="Predictable"
                                    OnDataBinding="RegisterForUpdate"
                                    ModelID='<%# ((OrderLineItem)Container.DataItem).ID %>'
                                    ModelPropertyName="Description"
                                    Text='<%# ((OrderLineItem)Container.DataItem).Description %>'
                                    Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Quantity">
                            <ItemTemplate>
                                <asp:TextBox runat="server" ID="QuantityTextBox" ClientIDMode="Predictable"
                                    OnDataBinding="RegisterForUpdate"
                                    ModelID='<%# ((OrderLineItem)Container.DataItem).ID %>'
                                    ModelPropertyName="Quantity"
                                    Text='<%# ((OrderLineItem)Container.DataItem).Quantity %>'
                                    Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Unit Price">
                            <ItemTemplate>
                                <asp:TextBox runat="server" ID="UnitPriceTextBox" ClientIDMode="Predictable"
                                    OnDataBinding="RegisterForUpdate"
                                    ModelID='<%# ((OrderLineItem)Container.DataItem).ID %>'
                                    ModelPropertyName="UnitPrice"
                                    Text='<%# ((OrderLineItem)Container.DataItem).UnitPrice %>'
                                    Enabled='<%# ((PurchasingDepartmentController)Controller).IsInEditMode %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Total Price">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="TotalPriceTextBox" ClientIDMode="Predictable"
                                    Text='<%# ((OrderLineItem)Container.DataItem).TotalPrice %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
